import { toDateString } from "xe-utils";
import { mapState } from "vuex";

export default {
  methods: {
    getLableValue(arr, value) {
      if (arr && arr.length) {
        const tempArr = arr.filter((item) => item.value == value);
        return tempArr[0]?.label;
      }
    },
    _formatterDatetime(row, column, cellValue, index) {
      return toDateString(cellValue);
    },
    _formatterDict(field, row, { property }, cellValue, index) {
      // INCOMPATIBLE_FIELD 位于页面同级目录下 config.js , 用于字典类型和接口类型不匹配时自动转换
      const { INCOMPATIBLE_FIELD, KV_MAP, OPTION_KEYS } = this;
      const handler = INCOMPATIBLE_FIELD[property];
      if (handler) {
        return KV_MAP[OPTION_KEYS[field]][handler[0](cellValue)];
      }
      return KV_MAP[OPTION_KEYS[field]][cellValue];
    },
  },
  filters: {
    _filterDatetime(value) {
      return toDateString(value);
    },
  },
  computed: {
    ...mapState("data", ["KV_MAP"]),
  },
};
